package unit9_11;

import java.security.spec.NamedParameterSpec;

//什么是反射
public class test4{
    public static void main(String[] args) throws Exception{
        user user = new stu();

//        方式一：通过对象获得
        Class c2 = user.getClass();
        System.out.println(c2);
//        方式二：forname获得
        Class c3 = Class.forName("unit9_11.stu");
        System.out.println(c3);
//        方式三：通过类名 class获得
        Class c4=stu.class;
        System.out.println(c4);
//        方式四：基本内置类型的包装类都有一个type属性
        Class<Integer> c5 = Integer.TYPE;
        System.out.println(c5);
//        获得父类类型
        Class superclass = c2.getSuperclass();
        System.out.println(superclass);


    }

}

//实体类
class user{
    public String name;

    public user() {
    }

    public user(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "user{" +
                "name='" + name + '\'' +
                '}';
    }
}

class techer extends user{
    public techer() {
        this.name="老师";
    }
}

class stu extends user{
    public stu() {
        this.name="学生";
    }
}

